/**
 * 
 */
package com.study.echart;

import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Line;

/**
 * @author Administrator
 * @date 2019年7月9日
 */
public class TestEchart {

	public static void main(String[] args) {
		testEchart();
	}
	public static String testEchart() {
		String result = "";
	    String[] types = {"ECS", "实例", "CPU", "MEM"};
	    int[][] datas = {
	            {120, 132, 101, 134, 90, 230, 210},
	            {220, 182, 191, 234, 290, 330, 310},
	            {150, 232, 201, 154, 190, 330, 410},
	            {150, 232, 201, 154, 190, 330, 410}
	    };

	    String title = "abc";

	    GsonOption option = new GsonOption();

	    option.title().text(title).x("left");// 大标题、位置

	    // 提示工具
	    option.tooltip().trigger(Trigger.axis);// 在轴上触发提示数据
	    // 工具栏
	    option.toolbox().show(true).feature(Tool.saveAsImage);// 显示,保存为图片

	    option.legend(types);// 图例

	    com.github.abel533.echarts.axis.CategoryAxis category = new com.github.abel533.echarts.axis.CategoryAxis();// 轴分类
	    category.data("2019-03-09", "2019-03-02", "2019-03-16");
	    category.boundaryGap(false);// 起始和结束两端空白策略

		 //循环数据
	    for (int i = 0; i < types.length; i++) {
	        Line line = new Line();// 三条线，三个对象
	        String type = types[i];
	        line.name(type).stack("总量");
	        for (int j = 0; j < datas[i].length; j++)
	            line.data(datas[i][j]);
	        option.series(line);
	    }

	    if (true) {// 横轴为类别、纵轴为值
	        option.xAxis(category);// x轴
	        // y轴
	        com.github.abel533.echarts.axis.ValueAxis ecsY = new com.github.abel533.echarts.axis.ValueAxis();
	        ecsY.name("ECS 台").position("left").axisLine().lineStyle().color("pink");

	        com.github.abel533.echarts.axis.ValueAxis insY = new com.github.abel533.echarts.axis.ValueAxis();
	        insY.name("容器实例 台").position("left").axisLine().lineStyle().color("yellow");

	        com.github.abel533.echarts.axis.ValueAxis cpuY = new com.github.abel533.echarts.axis.ValueAxis();
	        cpuY.name("CPU 核").position("right").axisLine().lineStyle().color("blue");

	        com.github.abel533.echarts.axis.ValueAxis memY = new com.github.abel533.echarts.axis.ValueAxis();
	        memY.name("MEM GB").position("right").axisLine().lineStyle().color("#777777");

	        option.yAxis(ecsY, insY);
	    } else {// 横轴为值、纵轴为类别
	        option.xAxis(new com.github.abel533.echarts.axis.ValueAxis());// x轴
	        option.yAxis(category);// y轴
	    }

	    String optionStr = option.toString().replace(" ", "").replace("\"", "'");
	    System.out.println(optionStr);
	    
	    result = optionStr;
	    return result;
	}
}
